<?php
/** .-------------------------------------------------------------------
 * |  Software: [HDCMS framework]
 * |      Site: www.hdcms.com
 * |-------------------------------------------------------------------
 * |    Author: 向军 <2300071698@qq.com>
 * |    WeChat: aihoudun
 * | Copyright (c) 2012-2019, www.houdunwang.com. All Rights Reserved.
 * '-------------------------------------------------------------------*/

namespace web\admin\controller;

class Type extends Common{

    private $db;

    public function __construct()
    {
        parent::__construct();
        $this->db=new \system\model\Type();
    }

    public function index(){
		//载入类型列表主页
        $data=$this->db->getAll();
        View::with('data',$data)->make();
	}
//    类型添加
    public function add(){
        //添加类型主页
        if(IS_POST){
            if($this->db->store()){
                message('操作成功',u('Type.index'),'success');
            }
            else{
                message($this->db->getError(),'back','error');
            }
        }
        View::make();
    }
//类型修改
    public function edit(){
        if(IS_POST){
            if($this->db->xiugai()){
                message('修改成功','Type.index','success');
            }else{
                message($this->db->getError(),'','error');
            }
        }
        //获取旧数据
        $tid=q('get.tid',0,'intval');
        $olddata=$this->db->where('tid',$tid)->first();
        //p($olddata);die;
        //载入修改主页
        View::with('olddata',$olddata)->make();
    }
    //类型删除
    public function del(){
        $tid=q('get.tid',0,'intval');
        $typeattrdata=Db::table('Type_attr')->where('tid',$tid)->first();
        if($typeattrdata){
            message('请先删除类型属性','','error');return;
        }else{
            $this->db->where('tid',$tid)->delete();
            message('删除成功',u('index'),'success');
        }

    }

}
